#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask
from flask import request
import json

app = Flask(__name__)

@app.route('/')
def index():
    return "BiServer, PassportServer, MidServer"

# mid server

@app.route('/strategic/userInfo/queryManhattanUserByUid', methods=['get', 'post'])
def queryManhattanUserByUid():
    mu = {}
    mu['errorCode'] = 0
    mu['errorMsg'] = 'OK'
    mu['data'] = {}
    mu['data']['mid'] = '1' + request.values['uid']
    mu['data']['uid'] = request.values['uid']
    mu['data']['role'] = 2
    mu['data']['cell'] = '13309090909'
    mu['data']['status'] = 0
    return json.dumps(mu)

@app.route('/manhattan/userAuthInfo/queryRealnameForMis', methods=['get', 'post'])
def queryRealnameForMis():
    return '''{
	"errorCode": 0,
	"errorMsg": "OK",
	"data": {
		"realnameAuthDOs": [
			{
				"id": 439,
				"mid": 11111111,
				"identityType": 1,
				"identityNo": "420117199201240417",
				"mobile": "15927634234",
				"realname": "程超",
				"dataSource": "dishuidai",
				"authorityCode": "zhongwang",
				"state": 0,
				"applicationNo": "",
				"bankCode": "",
				"bankAccountNo": "6217002870042857696",
				"isDeleted": 0,
				"createTime": 1487876683000,
				"updateTime": 31564800000,
				"deleteTime": 31536000000,
				"uid": 564471903297619,
				"role": ""
			}
		]
	},
	"httpStatus": null
}'''

@app.route('/manhattan/userAuthInfo/queryBankCardsForMis', methods=['get', 'post'])
def queryBankCardsForMis():
    return '''{
    	"errorCode": 0,
    	"errorMsg": "OK",
    	"data": {
    		"bankCards": [
    			{
    				"id": 87,
    				"mid": 11111111,
    				"bankCode": "cn",
    				"cardNo": "no5",
    				"accountName": "chengchao",
    				"cardName": "china",
    				"bindTime": 31536000000,
    				"unbindTime": 31536000000,
    				"isCreditCard": 0,
    				"validityFrom": 31536000000,
    				"validityTo": 31536000000,
    				"cvv2": "",
    				"mobile": "18612291952",
    				"authorityCode": "test",
    				"outId": "test",
    				"dataSource": "",
    				"bindingState": 0,
    				"applicationNo": "",
    				"isDeleted": 1,
    				"createTime": 1488550682000,
    				"updateTime": 1490636036000,
    				"deleteTime": 31536000000,
    				"uid": 1,
    				"role": "1"
    			}
    		]
    	},
    	"httpStatus": null
    }'''


# bi server

@app.route('/manhattan-drip-loan-api/queryDriverByUid.json', methods=['get', 'post'])
def queryDriverByUid():
    uids = json.loads(request.values['uids'])
    result = {'code': '0', 'message': '', 'data': []}
    pool = [ {"avgStar":4.92,"cancelCountLastHalfYearRate":0.018,"cancelCountLastMonthRate":0.078,"cellPhone":"13301249886","certId":"110102197011171135","cityId":1,"complaintCountLastHalfYearRate":0.003,"complaintCountLastMonthRate":0.011,"driverCreateTime":1404536612,"driverId":562950054647943,"driverType":"1,11","finishCountLastHalfYear":1438,"finishLastHalfYearMons":6,"gmtCreate":1472572800,"incomeLastHalfYear":24171.717,"increaseFinishCountLastHalfYear":0.751,"increaseFinishCountRankLastHalfYear":2.111,"lastMonthFinishCount":180,"name":"邵世杰","oneStarOrdersLastHalfYearRate":0.002,"oneStarOrdersLastMonthRate":0.006,"onlinedaysLastMonth":18,"onlinedaysLastQuarter":60,"reassignCountLastHalfYearRate":"","reassignCountLastMonthRate":"","source":"ACCESS_DATA","twoStarOrdersLastHalfYearRate":0.001,"twoStarOrdersLastMonthRate":0.006},{"avgStar":4.95,"cancelCountLastHalfYearRate":0.134,"cancelCountLastMonthRate":0.148,"cellPhone":"18611322517","certId":"110108196805054954","cityId":1,"complaintCountLastHalfYearRate":0,"complaintCountLastMonthRate":0,"driverCreateTime":1404797725,"driverId":565944402317312,"driverType":"1","finishCountLastHalfYear":82,"finishLastHalfYearMons":4,"gmtCreate":1472572800,"incomeLastHalfYear":1574.747,"increaseFinishCountLastHalfYear":1.317,"increaseFinishCountRankLastHalfYear":1.097,"lastMonthFinishCount":27,"name":"徐锋","oneStarOrdersLastHalfYearRate":0,"oneStarOrdersLastMonthRate":0,"onlinedaysLastMonth":11,"onlinedaysLastQuarter":25,"reassignCountLastHalfYearRate":"","reassignCountLastMonthRate":"","source":"ACCESS_DATA","twoStarOrdersLastHalfYearRate":0,"twoStarOrdersLastMonthRate":0},{"avgStar":4.98,"cancelCountLastHalfYearRate":0.013,"cancelCountLastMonthRate":0.04,"cellPhone":"18801337261","certId":"372523198210035310","cityId":1,"complaintCountLastHalfYearRate":0.001,"complaintCountLastMonthRate":0,"driverCreateTime":1404291510,"driverId":562950054422718,"driverType":"3,31","finishCountLastHalfYear":1579,"finishLastHalfYearMons":6,"gmtCreate":1469894400,"incomeLastHalfYear":0,"increaseFinishCountLastHalfYear":1.053,"increaseFinishCountRankLastHalfYear":1.575,"lastMonthFinishCount":277,"name":"冯海荣","oneStarOrdersLastHalfYearRate":0.001,"oneStarOrdersLastMonthRate":0.004,"onlinedaysLastMonth":28,"onlinedaysLastQuarter":82,"reassignCountLastHalfYearRate":"","reassignCountLastMonthRate":"","source":"APPLY_LOG_DATA","twoStarOrdersLastHalfYearRate":0,"twoStarOrdersLastMonthRate":0}]
    for i in range(len(uids)):
        result['data'].append(pool[i % len(pool)])
    return json.dumps(result)

@app.route('/manhattan-drip-loan-api/check/validate.json', methods=['get', 'post'])
def validate():
    return '{"code":0, "message":"success", "data":{ "code":0, "msg":"sucess" }}'

@app.route('/manhattan-drip-loan-api/queryAccessDrivers.json', methods=['get', 'post'])
def queryAccessDrivers():
    pageNum = int(request.values['pageNum'])
    if pageNum == 1:
        return '{"errorCode":0, "errorMsg":"success", "data":{ "total":3, "driverIdList": ["562950054647943","565944402317312","562950054422718"] }}'
    else:
        return '{"errorCode":0, "errorMsg":"success", "data":{ "total":0, "driverIdList": [] }}'

@app.route('/manhattan-drip-loan-api/core/data/queryDriver', methods=['get', 'post'])
def queryDriverData():
    return '{"errorCode":"0", "errorMsg":"s", "data":{ "driverId":"562950060470945", "driverIdCardNo":"620401196403131234", "driverName":"滴滴测试一", "driverPhone":"13652833785", "driverJoinModel":"1", "driverCreateTime":"2014-09-24 16:05:42", "driverAvgStar":"5", "last30DaysOnlineNum":"20", "last3MonthOnlineNum":"20", "didiIncreaseFinishCountLastHalfYear":"1.234", "didiIncreaseFinishCountRankLastHalfYear":"2.456", "last30DaysFinishOrderNum":"20", "last6MonthFinishOrderMonth":"4", "last6MonthDriverIncome":"1000.12", "last6MonthFinishOrderNum":"323", "last30DaysFinishOneStarOrdersRate":"0.001", "last6MonthFinishOneStarOrdersRate":"0.001", "last30DaysFinishTwoStarOrdersRate":"0.001", "last6MonthFinishTwoStarOrdersRate":"0.001", "last30DaysCancelOrdersRate":"0.001", "last6MonthCancelOrdersRate":"0.001", "last6MonthPasPhoneComplaintRate":"0.001", "last30DaysPasPhoneComplaintRate":"0.001"}}'


# passport server

@app.route('/passport/ticket/validate', methods=['get', 'post'])
def queryMid():
    return '{"age":9,"cell":"18080855080","channel":"102","country_code":"","create_time":1478268490,"datatype":0,"errno":0,"error":"OK","methodss":{"password":1478268490,"source":0},"origin_id":"1","role":2,"type":"LOGIN","uid":565269122460039,"uuid":""}'

@app.route('/passport/user/getUserinfoByUid', methods=['get','post'])
def getUserInfoByUid():
    return '{ "errno": 0, "error": "OK", "uid": "281475002991235", "cell": "13581513943", "countryId": "", "country_code": "", "origin_id": "1", "email": "", "role": 1, "age": 11, "created": 1401285265, "lastGood": 1501077633, "lastBad": 1498470662, "lastChange": 1483659184, "badCount": 0, "seqId": 0, "status": 0 }';

# baoshang

@app.route('/changeBankCard', methods=['get','post'])
def changeBankCard():
    res = '{"errorCode":"20009","errorMsg":"贷记卡不允许是还款卡！","sign":""}'
    res = '{"errorCode":"20006","errorMsg":"身份认证失败","sign":""}'
    res = '{"errorCode":"10000","errorMsg":"换绑还款卡成功","sign":""}'
    return res


if __name__ == "__main__":
    app.run(host='localhost', port=8888)
